home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9686 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: malloc question
  5. Date: 12 Mar 1996 20:20:06 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar12132006@qcd.lanl.gov>
  8. References: <4htonk$350@news.hklink.net> <4i492m$9jl@news1.warwick.net>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: acorn@warwick.net's message of Tue, 12 Mar 1996 16:35:35 GMT
  13.  
  14. In article <4i492m$9jl@news1.warwick.net>
  15. acorn@warwick.net (Peter Kohlberger) writes:
  16. <snip>
  17. PK: Basically, you need the cast because head is of type "pointer to ITEM"
  18. PK: and malloc returns type "pointer to void".  If you try it without the
  19. PK: cast, your compiler will complain "cannot convert *void to *ITEM".
  20.  
  21. If it does, _you_ should complain vehemently. Whatever it is a
  22. compiler for, it is not for the language called C.
  23.  
  24. PK: This is just the mechanics of the answer though, and I suspect this
  25. PK: is not what really puzzles you.
  26. PK: 
  27. PK: Without the cast, you can not convert *void into *ITEM; with the cast,
  28.  
  29. If you can create something called *void, you could probably also
  30. convert it to *ITEM :-)
  31.  
  32. More seriously, please be careful when posting junk. C defines
  33. void* ---> ITEM* (for any data or incomplete type ITEM) conversion to be
  34. allowed cast free. A compiler can impotently complain its
  35. unwillingness to do so (and if it does, I shall drag the compiler to
  36. exactly where it belongs), but a C compiler cannot refuse to compile
  37. strictly conformant C code.
  38.  
  39. PK: you are allowed to do the conversion.  If the conversion is allowed in
  40. PK: one manner, why is it not allowed in the other manner?
  41.  
  42. Your last statement suggests you have confused the two similar
  43. languages called C and C++.
  44.  
  45. Cheers
  46. Tanmoy
  47. --
  48. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  49. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  50. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  51. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  52. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  53. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  54.